package com.eedi.framework.notice.controller.org;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.notice.controller.org.vo.OrgNoticeResp;
import com.eedi.framework.notice.service.OrgNoticeService;
import com.eedi.framework.notify.controller.sys.vo.SysNoticePageReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.eedi.framework.web.core.util.WebFrameworkUtils;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import static com.eedi.framework.common.pojo.CommonResult.success;

@Tag(name = "机构界面 - 通知公告")
@RestController
@RequestMapping("/notice")
@Validated
public class OrgNoticeController {
    @Resource
    private OrgNoticeService orgNoticeService;

    @GetMapping("/page")
    @Operation(summary = "获取通知公告列表")
    @PermitAll
    public CommonResult<PageResult<OrgNoticeResp>> getNoticePage(SysNoticePageReq pageReqVO) {
        return success(orgNoticeService.page(WebFrameworkUtils.getLoginUserId(), pageReqVO));
    }

    @GetMapping("/read")
    @Operation(summary = "读取公告信息")
    @PermitAll
    public CommonResult<Void> read(@RequestParam("sysNoticeId") String sysNoticeId) {
        orgNoticeService.read(sysNoticeId, WebFrameworkUtils.getLoginUserId());
        return success(null);
    }

    @GetMapping("/read-all")
    @Operation(summary = "全部已读")
    @PermitAll
    public CommonResult<Void> readAll() {
        orgNoticeService.readAll(WebFrameworkUtils.getLoginUserId());
        return success(null);
    }
}
